package com.wtx.chapter03;

/**
 * @description: 选择排序
 * @author: wtx
 * @createDate: 2020/6/10
 */
public class SelectedSort {

    public static void sort(int[] array){

        int min = 0;
        int temp;
        for (int i = 0; i < array.length-1; i++) {
            min = i;
            for (int j = i+1; j < array.length; j++)
                if (array[j]<array[min])
                    min = j;

            temp = array[min];
            array[min] = array[i];
            array[i] = temp;
        }
    }

    public static void main(String[] args) {
        int[] arr = {10,20,5,8};
        SelectedSort.sort(arr);
        for (int i : arr)
            System.out.println(i);
    }
}
